package com.example.demo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 设置跨域，让前端允许访问后台的接口
 */
@Configuration
public class CORSConf implements WebMvcConfigurer{
    //配置跨域的
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")      // 设置映射
                .allowedOrigins("*")        // 设置域
                .allowedMethods("*")               // 设置请求的方式GET、POST等
                .allowedHeaders("*");              // 设置头
    }
    //配置虚拟路径和实体路径的映射关系
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/result/***")
                .addResourceLocations("file:D:/landingsheng/result/");
        registry.addResourceHandler("/content/***")
                .addResourceLocations("file:D:/landingsheng/content/");
    }
}